package com.yangming.springboot.utils;

import java.util.Base64;

/**
 * @创建人 ym
 * @创建时间 2021/3/12 0012
 * @描述
 **/
public class UserIdBase64 {


    /*
    * 对用户ID进行base64编码加密，下面是加密方法*/
    public static String encodeUserID(Integer userID){
        String base64UserIDEncoded = Base64.getEncoder().encodeToString((userID + "").getBytes());
        String currentStringBase64Encoded = Base64.getEncoder().encodeToString((System.currentTimeMillis() + "").getBytes());
        String keyString = currentStringBase64Encoded + currentStringBase64Encoded.substring(4, 8) + base64UserIDEncoded;
        byte [] codeBytes = keyString.getBytes();
        byte [] orderByte = new byte[codeBytes.length];
        for (int i = 0; i < codeBytes.length ; i++){
            orderByte[i] = codeBytes[codeBytes.length-i-1];
        }
        return new String(orderByte).replace("=", "#");
    }
}
